home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / progra1a / form1.frm < prev    next >
Text File  |  1999-09-03  |  5KB  |  189 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Program Closer"
  4.    ClientHeight    =   3255
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6870
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3255
  10.    ScaleWidth      =   6870
  11.    StartUpPosition =   2  'CenterScreen
  12.    Begin VB.CommandButton Command4 
  13.       Caption         =   "Exit"
  14.       Height          =   255
  15.       Left            =   2160
  16.       TabIndex        =   4
  17.       Top             =   2880
  18.       Width           =   615
  19.    End
  20.    Begin VB.Timer Timer1 
  21.       Interval        =   1
  22.       Left            =   6360
  23.       Top             =   2760
  24.    End
  25.    Begin VB.CommandButton Command3 
  26.       Caption         =   "Help"
  27.       Enabled         =   0   'False
  28.       Height          =   255
  29.       Left            =   2160
  30.       TabIndex        =   3
  31.       Top             =   2520
  32.       Width           =   615
  33.    End
  34.    Begin VB.CommandButton Command2 
  35.       Caption         =   "End Selected Task"
  36.       Enabled         =   0   'False
  37.       Height          =   255
  38.       Left            =   120
  39.       TabIndex        =   2
  40.       Top             =   2880
  41.       Width           =   1935
  42.    End
  43.    Begin VB.ListBox List1 
  44.       Height          =   1815
  45.       ItemData        =   "Form1.frx":0000
  46.       Left            =   120
  47.       List            =   "Form1.frx":0002
  48.       TabIndex        =   1
  49.       Top             =   600
  50.       Width           =   6615
  51.    End
  52.    Begin VB.CommandButton Command1 
  53.       Caption         =   "Show Running Tasks"
  54.       Height          =   255
  55.       Left            =   120
  56.       TabIndex        =   0
  57.       Top             =   2520
  58.       Width           =   1935
  59.    End
  60.    Begin VB.Label Label2 
  61.       Caption         =   $"Form1.frx":0004
  62.       Height          =   615
  63.       Left            =   2880
  64.       TabIndex        =   6
  65.       Top             =   2520
  66.       Width           =   3855
  67.       WordWrap        =   -1  'True
  68.    End
  69.    Begin VB.Label Label1 
  70.       BackColor       =   &H80000002&
  71.       Caption         =   "Program Closer by PWKraq"
  72.       BeginProperty Font 
  73.          Name            =   "MS Sans Serif"
  74.          Size            =   12
  75.          Charset         =   0
  76.          Weight          =   700
  77.          Underline       =   0   'False
  78.          Italic          =   0   'False
  79.          Strikethrough   =   0   'False
  80.       EndProperty
  81.       ForeColor       =   &H8000000E&
  82.       Height          =   375
  83.       Left            =   240
  84.       TabIndex        =   5
  85.       Top             =   120
  86.       Width           =   3375
  87.    End
  88.    Begin VB.Shape Shape2 
  89.       BorderColor     =   &H80000002&
  90.       BorderWidth     =   8
  91.       FillColor       =   &H80000002&
  92.       FillStyle       =   0  'Solid
  93.       Height          =   375
  94.       Left            =   120
  95.       Top             =   120
  96.       Width           =   6615
  97.    End
  98.    Begin VB.Shape Shape1 
  99.       BorderWidth     =   7
  100.       Height          =   3255
  101.       Left            =   0
  102.       Top             =   0
  103.       Width           =   6855
  104.    End
  105. End
  106. Attribute VB_Name = "Form1"
  107. Attribute VB_GlobalNameSpace = False
  108. Attribute VB_Creatable = False
  109. Attribute VB_PredeclaredId = True
  110. Attribute VB_Exposed = False
  111. Private Declare Function GetWindow Lib "user32" _
  112. (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  113. Private Declare Function GetParent Lib "user32" _
  114. (ByVal hwnd As Long) As Long
  115. Private Declare Function GetWindowTextLength Lib _
  116. "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
  117. Private Declare Function GetWindowText Lib "user32" _
  118. Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
  119. lpString As String, ByVal cch As Long) As Long
  120. Const GW_HWNDFIRST = 0
  121. Const GW_HWNDNEXT = 2
  122. Sub LoadTaskList()
  123. Dim CurrWnd As Long
  124. Dim Length As Long
  125. Dim TaskName As String
  126. Dim parent As Long
  127.  
  128. List1.Clear
  129. CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
  130.  
  131. While CurrWnd <> 0
  132. parent = GetParent(CurrWnd)
  133. Length = GetWindowTextLength(CurrWnd)
  134. TaskName = Space$(Length + 1)
  135. Length = GetWindowText(CurrWnd, TaskName, Length + 1)
  136. TaskName = Left$(TaskName, Len(TaskName) - 1)
  137.  
  138. If Length > 0 Then
  139.     If TaskName <> Me.Caption Then
  140.         If TaskName <> "taskmon" Then
  141.             List1.AddItem TaskName
  142.         End If
  143.     End If
  144. End If
  145. CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
  146. DoEvents
  147.  
  148. Wend
  149.  
  150. End Sub
  151.  
  152. Private Sub Command1_Click()
  153. LoadTaskList
  154. End Sub
  155.  
  156. Private Sub Command2_Click()
  157. On Error GoTo erlevel
  158. Dim winHwnd As Long
  159. Dim RetVal As Long
  160. winHwnd = FindWindow(vbNullString, List1.Text)
  161. Debug.Print winHwnd
  162. If winHwnd <> 0 Then
  163. RetVal = PostMessage(winHwnd, &H10, 0&, 0&)
  164. If RetVal = 0 Then
  165. MsgBox "Error posting message."
  166. End If
  167. Else: MsgBox List1.Text + " is not open."
  168. End If
  169. erlevel:
  170. LoadTaskList
  171. End Sub
  172.  
  173. Private Sub Command4_Click()
  174. End
  175. End Sub
  176.  
  177. Private Sub Form_Load()
  178. stayontop Me
  179. End Sub
  180.  
  181. Private Sub Timer1_Timer()
  182. If List1.Text = "" Then
  183.     Command2.Enabled = False
  184. Else
  185.     Command2.Enabled = True
  186. End If
  187. End Sub
  188.  
  189.